package com.zyh.controller;

import com.zyh.entity.Comment;
import com.zyh.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    CommentService service;

    @GetMapping("/{id}")
    public List<Comment> selectBySchoolId(@PathVariable("id") int id){
        List<Comment> comments = service.selectBySchoolId(id);
        Set userSet = new HashSet();
        for (Comment comment : comments) {
            userSet.add(comment.getUid());
        }
        return comments;
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable("id")int id){
        service.deletes(id);
    }
    @PostMapping("/")
    public void delete(@RequestBody Comment comment){
        comment.setCreateDate(new Date());
        service.insert(comment);
    }

}
